<template>
	<div>
		<div class="playlist">
			<div class="playlist__header-wrap"></div>
				<div class="playlist__content">
					<div>
						<div class="playlist__nav playlist__nav_today">
							<a class="playlist__btn playlist__btn_today customize-item">看昨天</a>
							<div class="playlist__date">
								<p class="playlist__today-date">{{today}}</p>
								<p class="playlist__today-rec">今日推荐</p>
							</div>
						</div>
						<div class="playlist__today-item-list">
							<a  @click="goDetail(item)" v-for="(item, index) in todayVideoSetList" v-bind:key="index" wx:key="index" class="playlist__today-item customize-expose customize-item" >
								<div class="playlist__today-bottom"></div>
								<div class="playlist__today-playlist">
									<div class="playlist__poster Lazy Lazy_loaded">
										<img :src="item.imageUrl">
									</div>
									<div class="playlist__desc">
										<i></i>
										<div class="playlist__text">
											<p class="playlist__amount">为你推荐 {{item.videoCount}} 个视频</p>
											<p class="playlist__title">{{item.title}}</p>
										</div>
									</div>
								</div>
							</a>
						</div>
					</div>
					<div v-for="(item, index) in beforeList" v-bind:key="index" wx:key="index">
						<div class="playlist__nav playlist__nav_past">
							<a @click="goTop()" class="playlist__btn playlist__btn_past customize-item">看今天</a>
							<div class="playlist__date">{{item.date}}</div>
						</div>
						<div class="playlist__past-item-list">
							<div class="playlist__past-item-wrap">
								<a @click="goDetail(it)" v-for="(it, idx) in item.videoSetList" v-bind:key="idx" wx:key="idx" v-bind:class="[idx % 2 == 1 ? 'playlist__past-item playlist__past-item_left customize-expose customize-item':'playlist__past-item customize-expose customize-item']" >
									<div class="playlist__past-playlist">
										<div class="playlist__past-poster Lazy Lazy_loaded">
											<img :src="it.imageUrl" >
										</div>
										<p class="playlist__past-view">{{it.playCount/10000}} 万播放</p>
									</div>
									<p class="playlist__past-title">{{it.title}}</p>
								</a>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
</template>
<script>
	let utils = require("@/common/util.js")
	export default {
		data() {
			return {
				showLoading: true,
				scrollLeft: 0,
				refreshing: false,
				refreshText: '下拉可以刷新',
				windowHeight: 0,
				navigationBarButtonTapTimes: 0,
				currDay: '',
				today:'',
				todayVideoSetList:[],
				beforeList:[]
			}
		},
		components: {
		},
		onLoad: function() {
			this.windowHeight = uni.getSystemInfoSync().windowHeight;
			this.getList();
		},
		onPullDownRefresh(event){
			this.refreshText = '正在刷新...';
			this.refreshing = true;
			this.getList(1);
		},
		onReachBottom(event){
			this.getList(2);
		},
		onShareAppMessage() {
			return {
				title: '涨知识-热门视频',
				path: '/pages/hot-v/miui/mvd'
			}
		},
		methods: {
			getList(action = 1) {
				var that = this;
				that.showLoading = true;
				uni.request({
					url: 'https://bukaa.cn/api-cms/hot/miui/video/list?beginDate=' + that.currDay,
					success: (result) => {
						var data = result.data;
						if (data.status === 'ok' && data.data.data && data.data.data.videoSetData) {
							var dataList = data.data.data.videoSetData;
							if(!that.currDay){ //第一次请求
								var todayData = dataList[0];
								that.today = todayData.date;
								that.todayVideoSetList = todayData.videoSetList;
								for (let i = 1; i < dataList.length; i++) {
									that.beforeList.push(dataList[i]);
									that.currDay = dataList[i].date;
								}
							}else{
								for (let i = 1; i < dataList.length; i++) {
									that.beforeList.push(dataList[i]);
									that.currDay = dataList[i].date;
								}
							}
						}
					},
					complete:()=>{
						that.showLoading = false;
						uni.stopPullDownRefresh();
					}
				});
			},
			goTop: function(){
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
			},
			  /**
			 * 时间秒数格式化
			 * @param s 时间戳（单位：秒）
			 * @returns {*} 格式化后的时分秒
			 */
			secToTime(s) {
				var t = "";
				if(s > -1){
					var hour = Math.floor(s/3600);
					var min = Math.floor(s/60) % 60;
					var sec = s % 60;
					if(hour < 10 && hour > 0) {
						t = '0'+ hour + ":";
					} else if(hour >= 10) {
						t = hour + ":";
					}

					if(min < 10){t += "0";}
					t += min + " : ";
					if(sec < 10){t += "0";}
					t += sec.toFixed(0);
				}
				return t;
			},
			goDetail(detail) {
				uni.navigateTo({
					url: '/pages/hot-v/miui/detail?query=' + encodeURIComponent(JSON.stringify(detail))
				});
			},
			loadMore() {
				this.getList(2);
			},
			
			onRefresh(event) {
				this.refreshText = '正在刷新...';
				this.refreshing = true;
				this.getList();
			},
		}
	}
</script>
<style>
@import url("../../../static/css/mymovie/mymovie.css");
</style>
